package com.tusuo.stds.ui.fillinfo;

import android.support.annotation.NonNull;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.tusuo.stds.R;
import com.tusuo.stds.ui.BaseToolbarActivity;
import com.tusuo.stds.ui.ToolbarOwner;
import com.tusuo.stds.ui.login.ThirdLoginUserInfo;
import com.tusuo.stds.util.Utils;

import org.androidannotations.annotations.AfterViews;
import org.androidannotations.annotations.Click;
import org.androidannotations.annotations.EActivity;
import org.androidannotations.annotations.ViewById;
import org.androidannotations.annotations.res.ColorRes;
import org.androidannotations.annotations.res.StringRes;
import org.parceler.Parcels;

import java.util.ArrayList;
import java.util.List;

import myandroid.library.util.ApplicationHelper;

@EActivity(R.layout.activity_fill_info)
public class FillInfoActivity extends BaseToolbarActivity<FillInfoView, FillInfoPresenter>
                                implements FillInfoView {

    @ViewById(R.id.fill_info_tv_name)
    TextView tvName;

    @ViewById(R.id.fill_info_iv_icon)
    ImageView ivIcon;

    @StringRes(R.string.toolbar_title_fill_info)
    String toolbarTitle;

    @ColorRes(R.color.colorPrimary)
    int toolbarBgColor;
    @ColorRes(R.color.textColorPrimary)
    int toolbarTextColor;

    private ThirdLoginUserInfo mThirdLoginUserInfo;

    @AfterViews
    void afterViews() {
        setupUI(this, toolbarBgColor, toolbarTextColor);

        List<ToolbarOwner.MenuAction> menuActionList = new ArrayList<>();

        ToolbarOwner.Config config = new ToolbarOwner.Config(toolbarTitle, true, R.drawable.ic_back_dark, menuActionList);
        mToolbarOwner.setConfig(config);

        mThirdLoginUserInfo = Parcels.unwrap(getIntent().getParcelableExtra(ThirdLoginUserInfo.EXTRA_NAME));

        tvName.setText(mThirdLoginUserInfo.nickName);

        Glide.with(this).load(Utils.getCorrectImageUrl(mThirdLoginUserInfo.userIcon)).centerCrop().into(ivIcon);

        ApplicationHelper.getInstance().addActivity(this);
    }

    @NonNull
    @Override
    public FillInfoPresenter createPresenter() {
        return new FillInfoPresenter(this);
    }

    @Click(R.id.fill_info_btn_link_account)
    void clickLinkAccountBtn() {
        if (Utils.UI.isFastDoubleClick()) {
            return;
        }

        presenter.linkAccount(mThirdLoginUserInfo);
    }

    @Click(R.id.fill_info_btn_bind_new)
    void clickBindNewBtn() {
        if (Utils.UI.isFastDoubleClick()) {
            return;
        }

        presenter.bindNew(mThirdLoginUserInfo);
    }
}
